<?php $base_path = Yii::app()->baseUrl; ?>
<?php
$cate = $data['cate'];
?>
<div class="block">
    <div class="block_head">
        <div class="bheadl"></div>
        <div class="bheadr"></div>
        <h2><?php echo Yii::app()->controller->action->id == 'add' ? 'Thêm mới' : 'Sửa'; ?> danh mục</h2>
    </div>

    <div class="block_content">
        <?php echo showMessage(); ?>

        <form action="" method="post" enctype="multipart/form-data">
            <p>
                <label for="name">Tên danh mục:</label><br />
                <input type="text" class="text small" name="name" id="name" value="<?php echo str2str($cate['name']); ?>" />
            </p>
            <?php
            if (!empty($data['listCategory'])) {
                ?>
                <p>
                    <label for="parent_id">Danh mục cha:</label><br />
                    <select name="parent_id" id="parent_id" class="styled">                        
                        <?php
                        foreach ($data['listCategory'] as $item) {
                            echo '<option ' . (($cate['parent_id'] == $item->id | $_GET['parent_id'] == $item->id) ? 'selected=""' : '') . ' value="' . $item->id . '">' . $item->name . '</option>';
                        }
                        ?>
                    </select>
                </p>
                <?php
            }
            ?>
            <p>
                <label for="keyword">Keyword:</label><br />
                <textarea name="keyword" id="keyword"><?php echo $cate['keyword']; ?></textarea>
            </p>
            <p>
                <label for="description">Description:</label><br />
                <textarea name="description" id="description"><?php echo $cate['description']; ?></textarea>
            </p>            
            <?php
            if ((!isset($_GET['parent_id']) && empty($cate)) | (!empty($cate) && $cate['parent_id'] == 0)) {
                ?>
                <p class="fileupload">
                    <label>Banner:</label><br />
                    <input type="file" id="banner" name="banner" />
                    <span id="uploadmsg">Jpg, gif, png and pdf files only. Max size 3mb.</span>
                    <?php
                    if (!empty($cate['banner'])) {
                        echo '<br /><img src="' . $base_path . '/upload/category/banner/' . $cate['banner'] . '" style="max-width: 150px; max-height: 150px;" />';
                    }
                    ?>
                </p>

                <p>
                    <input type="checkbox" class="checkbox" name="banner_show" <?php if ($cate['banner_show'] == 1) echo 'checked=""'; ?> value="1" id="banner_show" /> <label for="banner_show">Hiển thị banner</label>
                </p>                
                <?php
            }
            ?>
            <p class="fileupload">
                <label>Icon:</label><br />
                <input type="file" id="icon" name="icon" />
                <span id="uploadmsg">Jpg, gif, png and pdf files only. Max size 3mb.</span>
                <?php
                    if (!empty($cate['icon'])) {
                        echo '<br /><img src="' . $base_path . '/upload/category/icon/' . $cate['icon'] . '" style="max-width: 100px; max-height: 100px;" />';
                    }
                    ?>
            </p>
            <p><label>Status:</label><br />
                <select name="status" class="styled">
                    <option value="1" selected="">Hiện</option>
                    <option value="0" <?php if (!empty($cate) && $cate['status'] === 0) echo 'selected=""'; ?>>Ẩn</option>
                </select>
            </p>
            <hr />
            <p>
                <input type="submit" class="submit small" value="Submit" />
                <input type="button" class="submit mid" value="Cancel" onclick="window.location='<?php echo $this->createUrl('category/index') ?>';" />
            </p>
        </form>
    </div>
    <div class="bendl"></div>
    <div class="bendr"></div>
</div>